package GUI;

/**
 * If a teacher teaches more then one course in our school the administration chooses
 * from which course she wants a replacement
 */

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Vector;

public class SubTeacherSelCrs extends JPanel {
	private JLabel label = null;
	private JLabel label_1 = null;
	private JComboBox cBSelCourse = null;
	private JButton btnNext = null;
	
	public Login myLoginFrame = null;
	public UserAdmin user=null;
	public AdminMainMenu amn=null;	
	private SubTeacherSelCls teacherAllocScrn_3 = null;
	private String selCourse = null;
	
	
	public JComboBox getcBSelCourse(AdminMainMenu amn)
	{
		int i;
		Vector<CourseOfClass> data = new Vector<CourseOfClass>();
		Vector<String> convert = new Vector<String>();
		
		for(i=0;i<amn.user.DataForEx.CoursesOfClasses.size();i++)
		{
			if(amn.user.DataForEx.getSelSubsTeacher().endsWith(amn.user.DataForEx.CoursesOfClasses.get(i).TeacherID))
			{
				
				System.out.println("Test1: "+amn.user.DataForEx.CoursesOfClasses.get(i).Cid + amn.user.DataForEx.CoursesOfClasses.get(i).TeacherID );
				data.add(amn.user.DataForEx.CoursesOfClasses.get(i));
			}
		}
		for(i=0;i<data.size();i++)
		{
			convert.add(data.get(i).CourseName+" "+data.get(i).Cid);
		}
		

		if(cBSelCourse==null)
		{
			cBSelCourse = new JComboBox(convert);
			cBSelCourse.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					selCourse=cBSelCourse.getSelectedItem().toString();
			 		System.out.println(selCourse);
					
					
				}
			});
			cBSelCourse.setBounds(256, 77, 178, 20);
		}
		return cBSelCourse;
	}
	
	
	public JButton getBtnNext(final AdminMainMenu amn)
	{
		if(btnNext==null)
		{
		btnNext = new JButton("Next");
		btnNext.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				teacherAllocScrn_3 = null;
				amn.user.DataForEx.setSelCourse(selCourse);
				teacherAllocScrn_3 = amn.getTeacherAllocScrn_3();
				amn.setContentPane(teacherAllocScrn_3);
			}
		});
		btnNext.setBounds(517, 315, 89, 23);
		}
		
		return  btnNext ;
		
	}
	
	public void initialize(AdminMainMenu amn)
	{
		setLayout(null);
		
		 label = new JLabel("Exceptional request - Teacher allocation from class");
		label.setBounds(242, 11, 243, 14);
		add(label);
		
		label_1 = new JLabel("Select course:");
		label_1.setBounds(64, 80, 138, 14);
		add(label_1);
		add(getcBSelCourse(amn));
		add(getBtnNext(amn));
		
	}
	
	
	
	
	
	public SubTeacherSelCrs(AdminMainMenu amn) {
		super();
		initialize(amn);
		
	}
}
